import axios from 'axios'
import qs from 'qs'
let request = axios.create({
    baseURL: 'http://localhost:2345/',
    timeout: 5000,
})

request.interceptors.request.use(config => {
    //前台向后台发送数据时
    config.method == 'post' ? config.data = qs.stringify({ ...config.data }) : config.params = { ...config.params }
    config.headers['Content-Type'] = 'application/X-www-form-urlencoded';
    return config
}, error => {
    return Promise.reject(error)
}
)

request.interceptors.response.use(response => {
    return response
},
    error => {
        return Promise.reject(error)
    })

export default request